package com.ruoyi.yuyuan.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.yuyuan.Entity.BlogAgreement;
import com.ruoyi.yuyuan.Entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    @Update("update tb_blog_comments set likes=likes+1 where id = #{id} and status < 2")
    boolean addLike(Long id);

    @Update("update tb_blog_comments set likes=likes-1 where id = #{id} and status < 2")
    boolean subLike(Long id);

    @Select("select max(id) from tb_blog_comments where status < 2 and blog_id = #{blogId} order by id limit 1")
    Long getMaxStartId(Long blogId);

    @Select("select * from tb_blog_comments where blog_id = #{blogId} and id < #{startId} and status < 2 order by create_time ASC, id ASC limit 6")
    List<Comment> getPageByBlogId(Long blogId, Long startId);
}
